package com.yanqu.road.dao.impl.activity.dafuweng;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.dafuweng.DFWBossConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class DFWBossConfigDaoImpl extends TempDao {

    private static final String sql = "select * from t_s_monopoly_boss where activityId = ?";

    public Map<Integer, DFWBossConfig> getDFWBossConfigMap(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, DFWBossConfig> map = new ConcurrentHashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(sql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                DFWBossConfig config = new DFWBossConfig();
                config.setBossType(rs.getInt("id"));
                config.setAppearance(rs.getString("appearance"));
                config.setNum(rs.getInt("num"));
                config.setHp(rs.getInt("hp"));
                config.setRewards(rs.getString("rewards"));
                config.setWeight(rs.getInt("weight"));
                config.setSort(rs.getInt("sort"));
                map.put(config.getBossType(), config);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

}
